package com.yz.lzq.liwushuo.ui.modules.home.boutique;

import android.content.Context;

import com.yz.lzq.liwushuo.config.NumberUtil;
import com.yz.lzq.liwushuo.http.OnGetNetDataListener;
import com.yz.lzq.liwushuo.jsonbean.home.boutique.HomeBoutiqueBannerBean;
import com.yz.lzq.liwushuo.jsonbean.home.boutique.HomeBoutiqueFenLeiBean;
import com.yz.lzq.liwushuo.jsonbean.home.boutique.HomeBoutiqueRecycleBean;
import com.yz.lzq.liwushuo.ui.modules.comminterface.OnGetSharedPerfenceDataListener;
import com.yz.lzq.liwushuo.ui.modules.home.nomal.HomeNomalContract;
import com.yz.lzq.liwushuo.ui.modules.home.nomal.HomeNomalModel;
import com.yz.lzq.liwushuo.ui.setting.SettingActivityPresenter;

/**
 * Created by Administrator on 2016/12/13.
 * home页面的精品fragment的中间人模块
 */

public class HomeBoutiquePresenter {
    private HomeBoutiqueContract.HomeBoutiqueViewInterface viewInterface = null;
    private HomeBoutiqueContract.HomeBoutiqueModelInterface modelInterface = null;
    //用户身份设置功能模块的中间人层对象，用于获取用户信息
    private SettingActivityPresenter settingActivityPresenter = null;
    private HomeNomalContract.HomeNomalModelInterface nomalModelInterface = null;
    private int offSet = 0;

    public HomeBoutiquePresenter(Context context, HomeBoutiqueContract.HomeBoutiqueViewInterface viewInterface) {
        this.viewInterface = viewInterface;
        modelInterface = new HomeBoutiqueModel();
        nomalModelInterface = new HomeNomalModel();
        settingActivityPresenter = new SettingActivityPresenter(context);
    }

    /**
     * 请求数据展示banner
     */
    public void showBanner() {
        modelInterface.LoadHomeJinPinBannerBean(new OnGetNetDataListener<HomeBoutiqueBannerBean>() {
            @Override
            public void onGetDataSucess(HomeBoutiqueBannerBean data) {
                viewInterface.getHomeJingPinBannerBean(data);
            }

            @Override
            public void onGetDataFalied(Throwable t) {

            }
        });
    }

    /**
     * 请求数据展示FenLei视图
     */
    public void showFenLei() {
        settingActivityPresenter.setOnGetUserSharedPerfence(new OnGetSharedPerfenceDataListener() {
            @Override
            public void onGetGenderAndGenration(int gender, int genration) {
                modelInterface.LoadHomeJinFenLeiBean(gender, genration, new OnGetNetDataListener<HomeBoutiqueFenLeiBean>() {
                    @Override
                    public void onGetDataSucess(HomeBoutiqueFenLeiBean data) {
                        viewInterface.getHomeBoutiqueFenLeiBean(data);
                    }

                    @Override
                    public void onGetDataFalied(Throwable t) {

                    }
                });

            }
        });
    }

    /**
     * 请求数据展示RecyclerView视图
     * AD=2&gender=1&generation=2&LIMIT=20&OFFSET=0
     */
    public void showRecycleView(final boolean loadMore) {

        settingActivityPresenter.setOnGetUserSharedPerfence(new OnGetSharedPerfenceDataListener() {
            @Override
            public void onGetGenderAndGenration(int gender, int genration) {
                if (loadMore) {
                    offSet += 20;
                } else {
                    offSet = 0;
                }
                nomalModelInterface.LoadHomeNomalRecycleViewBean(NumberUtil.AD, NumberUtil.HOME_BOUTIQUE_RECYCLERVIEW_ID, gender, genration, NumberUtil.LIMIT, offSet, new OnGetNetDataListener<HomeBoutiqueRecycleBean>() {
                    @Override
                    public void onGetDataSucess(HomeBoutiqueRecycleBean data) {
                        viewInterface.getHomeBoutiqueRecycleBean(data);
                    }

                    @Override
                    public void onGetDataFalied(Throwable t) {

                    }
                }, loadMore);
            }
        });
    }

}
